import { IResponseItem } from "@/api/dxn/financialManager/handAccount/types"
import TooltipText from "@/components/common/tooltipText"
import { parseTime } from "@/utils"
import { getGameTypeName } from "@/utils/replay"
import { handleNumber, handleNumberColor } from "@/utils/util"

interface RecordTypeGameName {
	gameName?: string
	gameType: number
}

const useDxnFinancialManagerColumn = (newFormat: any) => {
	const serialNumber = {
		dataIndex: "serialNumber",
		align: "center",
		key: "dxnFinancialManager_serialNumber",
		width: 100,
		title: newFormat("dxn.game_rule.serial_number"),
		render: (_text: any, record: any, index: number) => <span>{index + 1}</span>
	}
	const auditBillId = {
		dataIndex: "auditBillId",
		align: "center",
		key: "dxnFinancialManager_auditBillId",
		width: 180,
		title: newFormat("dxn.hand_account.AuditBillId"),
		render: (_text: any) => {
			return <TooltipText text={_text || "-"} />
		}
	}

	const accountHandTypeName = {
		dataIndex: "accountHandTypeName",
		align: "center",
		key: "dxnFinancialManager_accountHandTypeName",
		width: 100,
		title: newFormat("dxn.hand_account.accountType"),
		render: (_text: any, record: any) => {
			return <span>{record.accountHandTypeName || record.type === 0 ? "每桌核账" : "-"}</span>
		}
	}

	const accountHandStatus = {
		dataIndex: "status",
		align: "center",
		key: "dxnFinancialManager_status",
		width: 100,
		title: newFormat("dxn.hand_account.status"),
		render: (_text: any) => {
			const statusMap = ["dxn.financial_manager.inprogress", "dxn.financial_manager.accounted"]
			return <span>{newFormat(statusMap[_text]) || "-"}</span>
		}
	}

	const gameName = {
		dataIndex: "gameName",
		align: "center",
		key: "dxnFinancialManager_gameName",
		width: 100,
		title: newFormat("dxn.hand_account.gameName"),
		render: (_text: any, record: RecordTypeGameName) => {
			return <span>{record.gameName || getGameTypeName(record.gameType) || "-"}</span>
		}
	}

	const startTime = {
		dataIndex: "startTime",
		align: "center",
		key: "dxnFinancialManager_startTime",
		width: 160,
		title: newFormat("dxn.hand_account.startTime"),
		render: (_text: any, record: IResponseItem) => <span>{parseTime(record.startTime)}</span>
	}

	const endTime = {
		dataIndex: "endTime",
		align: "center",
		key: "dxnFinancialManager_endTime",
		width: 160,
		title: newFormat("dxn.hand_account.endTime"),
		render: (_text: any, record: IResponseItem) => <span>{parseTime(record.endTime)}</span>
	}

	const totalBetBookAccountChange = {
		dataIndex: "totalBetBookAccountChange",
		align: "center",
		key: "dxnFinancialManager_totalBetBookAccountChange",
		width: 160,
		title: newFormat("dxn.hand_account.totalBetBookAccountChange"),
		render: (_text: any, record: IResponseItem) => {
			return <TooltipText text={handleNumber(" ", record.totalBetAccountChange?.toString())} />
		}
	}

	const invalidSidePoolAccountChange = {
		dataIndex: "invalidSidePoolAccountChange",
		align: "center",
		key: "dxnFinancialManager_invalidSidePoolAccountChange",
		width: 160,
		title: newFormat("dxn.hand_account.invalidSidePoolAccountChange"),
		render: (_text: any, record: IResponseItem) => {
			return <TooltipText text={handleNumber(" ", record.invalidSidePoolAccountChange?.toString())} />
		}
	}
	const totalPayoutAccountChange = {
		dataIndex: "totalPayoutAccountChange",
		align: "center",
		key: "dxnFinancialManager_totalPayoutAccountChange",
		width: 160,
		title: newFormat("dxn.hand_account.totalPayoutAccountChange"),
		render: (_text: any, record: IResponseItem) => {
			return <TooltipText text={handleNumber(" ", record.totalPayoutAccountChange?.toString())} />
		}
	}

	const totalValidBetRecord = {
		dataIndex: "totalValidBetRecord",
		align: "center",
		key: "dxnFinancialManager_totalValidBetRecord",
		width: 160,
		title: newFormat("dxn.hand_account.totalValidBetRecord"),
		render: (_text: any, record: IResponseItem) => {
			return <TooltipText text={handleNumber(" ", record.totalValidBetRecord?.toString())} />
		}
	}

	const handServiceCharge = {
		dataIndex: "handServiceCharge",
		align: "center",
		key: "dxnFinancialManager_handServiceCharge",
		width: 160,
		title: newFormat("dxn.hand_account.handServiceCharge"),
		render: (_text: any, record: any) => {
			return <TooltipText text={handleNumber(record.currency || " ", _text)} />
		}
	}

	const blayersBringIn = {
		dataIndex: "players_bring_in",
		align: "center",
		key: "dxnFinancialManager_players_bring_in",
		width: 160,
		title: newFormat("dxn.hand_account.players_bring_in"),
		render: (_text: any, record: any) => <TooltipText text={handleNumber(record.currency, record.bringIn)} />
	}

	const playersBringOut = {
		dataIndex: "players_bring_out",
		align: "center",
		key: "dxnFinancialManager_players_bring_out",
		width: 160,
		title: newFormat("dxn.hand_account.players_bring_out"),
		render: (_text: any, record: any) => <TooltipText text={handleNumber(record.currency, record.bringOut)} />
	}

	const insuranceNetAmount = {
		dataIndex: "insuredNetAmount",
		align: "center",
		key: "dxnFinancialManager_insuredNetAmount",
		width: 160,
		title: newFormat("dxn.hand_account.insuredNetAmount"),
		render: (_text: any, record: any) => {
			return (
				<span style={{ color: handleNumberColor(_text) }}>
					<TooltipText text={handleNumber(record.currency || " ", _text)} />
				</span>
			)
		}
	}

	const squidBringInAmount = {
		dataIndex: "squidBringInAmount",
		align: "center",
		key: "dxnFinancialManager_squidBringInAmount",
		width: 160,
		title: newFormat("dxn.financial_manager.squid_bring_in_amount"),
		render: (_text: any, record: any) => {
			return <TooltipText text={handleNumber(record.currency || " ", record.squidBringInAmount?.toString())} />
		}
	}

	const squidBringOutAmount = {
		dataIndex: "squidBringOutAmount",
		align: "center",
		key: "dxnFinancialManager_squidBringOutAmount",
		width: 160,
		title: newFormat("dxn.financial_manager.squid_bring_in_amount"),
		render: (_text: any, record: any) => {
			return <TooltipText text={handleNumber(record.currency || " ", record.squidBringOutAmount?.toString())} />
		}
	}

	const squidPay = {
		dataIndex: "squidPay",
		align: "center",
		key: "dxnFinancialManager_squidPay",
		width: 160,
		title: newFormat("dxn.financial_manager.squid_pay"),
		render: (_text: any, record: any) => {
			return (
				<span style={{ color: handleNumberColor(record.squidPay) }}>
					<TooltipText text={handleNumber(record.currency || " ", record.squidPay?.toString())} />
				</span>
			)
		}
	}

	const checkAccountResult = {
		dataIndex: "checkAccountResult",
		align: "center",
		key: "dxnFinancialManager_checkAccountResult",
		width: 160,
		title: newFormat("dxn.hand_account.checkAccountResult"),
		render: (_text: any, record: any) => {
			const checkAccountResultMap = [
				"dxn.financial_manager.not_accounted",
				"dxn.financial_manager.accounting_successful",
				"dxn.financial_manager.reconciliation_failed"
			]
			return (
				<span style={{ color: record.verifyResult === 2 ? "red" : "" }}>
					{newFormat(checkAccountResultMap[record.checkAccountResult || record.verifyResult]) || "-"}
				</span>
			)
		}
	}

	return {
		serialNumber,
		auditBillId,
		accountHandStatus,
		accountHandTypeName,
		checkAccountResult,
		endTime,
		gameName,
		handServiceCharge,
		invalidSidePoolAccountChange,
		startTime,
		totalBetBookAccountChange,
		totalPayoutAccountChange,
		totalValidBetRecord,
		blayersBringIn,
		playersBringOut,
		insuranceNetAmount,
		squidBringInAmount,
		squidBringOutAmount,
		squidPay
	}
}

export default useDxnFinancialManagerColumn
